 
function removePanel() {
    var tab = $('#tabs').tabs('getSelected');
    if (tab) {
        var index = $('#tabs').tabs('getTabIndex', tab);
        $('#tabs').tabs('close', index);
    }
}


function tabClose() {
    /*双击关闭TAB选项卡*/
    $(".tabs-inner").dblclick(function () {
        var subtitle = $(this).children(".tabs-closable").text();
        $('#tabs').tabs('close', subtitle);
    })
    /*为选项卡绑定右键*/
    $(".tabs-inner").bind('contextmenu', function (e) {
        $('#mm').menu('show', {
            left: e.pageX,
            top: e.pageY
        });

        var subtitle = $(this).children(".tabs-closable").text();

        $('#mm').data("currtab", subtitle);
        $('#tabs').tabs('select', subtitle);
        return false;
    });
}

//绑定右键菜单事件
function tabCloseEven() {
    //刷新
    $('#mm-tabupdate').click(function () {
        var currTab = $('#tabs').tabs('getSelected');
        var url = $(currTab.panel('options').content).attr('src');
        if (url != undefined && currTab.panel('options').title != '首页') {
            $('#tabs').tabs('update', {
                tab: currTab,
                options: {
                    content: createFrame(url)
                }
            })
        }
    })
    //关闭当前
    $('#mm-tabclose').click(function () {
        var currtab_title = $('#mm').data("currtab");
        $('#tabs').tabs('close', currtab_title);
    })
    //全部关闭
    $('#mm-tabcloseall').click(function () {
        $('.tabs-inner span').each(function (i, n) {
            var t = $(n).text();
            if (t != '首页') {
                $('#tabs').tabs('close', t);
            }
        });
    });
    //关闭除当前之外的TAB
    $('#mm-tabcloseother').click(function () {
        var prevall = $('.tabs-selected').prevAll();
        var nextall = $('.tabs-selected').nextAll();
        if (prevall.length > 0) {
            prevall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                if (t != '首页') {
                    $('#tabs').tabs('close', t);
                }
            });
        }
        if (nextall.length > 0) {
            nextall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                if (t != '首页') {
                    $('#tabs').tabs('close', t);
                }
            });
        }
        return false;
    });
    //关闭当前右侧的TAB
    $('#mm-tabcloseright').click(function () {
        var nextall = $('.tabs-selected').nextAll();
        if (nextall.length == 0) {
            //msgShow('系统提示','后边没有啦~~','error');
            alert('后边没有啦~~');
            return false;
        }
        nextall.each(function (i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            $('#tabs').tabs('close', t);
        });
        return false;
    });
    //关闭当前左侧的TAB
    $('#mm-tabcloseleft').click(function () {
        var prevall = $('.tabs-selected').prevAll();
        if (prevall.length == 0) {
            alert('到头了，前边没有啦~~');
            return false;
        }
        prevall.each(function (i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            $('#tabs').tabs('close', t);
        });
        return false;
    });

    //退出
    $("#mm-exit").click(function () {
        $('#mm').menu('hide');
    })
}
function setCookie(name, value) {//两个参数，一个是cookie的名子，一个是值
    var Days = 30; //此 cookie 将被保存 30 天
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

function getCookie(name) {//取cookies函数        
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}

function ShowException(data) {
    if (typeof (data) == 'object') {
        $('#PopWindowContet').html(data.responseText);
    }
    else {
        $('#PopWindowContet').html(data);
    }
    $('#PopWindow').window({
        width: 160,
        title:'异常',
        height: 6,
        modal: true
    });
    $('#PopWindow').window('open');
} 
 
 
 

function addPanel(id, title, src,_iconCls) {
    var panelwidth = $('#tabs').tabs('getTab', 0).width()-25; 
    var panelHeight = $('#tabs').tabs('getTab', 0).height()-25; 
    $('#tabs').tabs('add', {
        //iconCls: 'icon-edit'  ,
        title: title,
        content: '<iframe scrolling="yes" frameborder="0"  src="' + src + '" style="width:'+panelwidth+'px;height:' + panelHeight + 'px;padding:10px;"></iframe>',
        closable: true
    });
    tabClose();
}

 
function baseGoUrl(url) {
    window.location.href = url;
}

function ShowPopWindow(_title, _url) {
    var _width=$(window).width() - 200;
    var _height=$(window).height() - 100; 
    $('#PopWindow').dialog({
        title:  _title, 
        width: _width,
        height: _height,
        closed: false,
        cache: false, 
        content: '<iframe scrolling="no" frameborder="0"  src="' + _url + '" style="width:100%;height:' + (_height -40)+ 'px"; overflow:hidden"></iframe>',
        modal: true
    });
} 
 

function  ShowPopWindowUrl(id, title, url, w_width, w_height) {
    var _width = 720;
    var _height = $(window).height()*0.8 ;  
    if (w_width != undefined) {
        _width = w_width;
        if (w_width && (''+w_width).indexOf('.') > 0) {
            _width = $(window).width() * parseFloat(w_width);
        }
    }
    if (w_height != undefined) {
        _height = w_height;
        if (w_height && (''+w_height).indexOf('.') > 0) {
            _height = $(window).height() * parseFloat(w_height);
        }
    }

    $('#PopWindow').dialog({
        title:  title,
        //iconCls: 'icon-edit'   ,
        width: _width,
        height: _height,
        closed: false,
        cache: false,
        content: '<iframe scrolling="yes" frameborder="0"  src="' + url + '" style="width:100%;height:99%";margin:10px;"></iframe>',
        modal: true
    });
}

 
function ClosePopWindow() {
    $('#PopWindow').dialog({
        closed: true,
        content: ' a'
    });

}

function InintChart(divid, type, title, memo, ytitle) {
    $.ajax({
        async: true,
        type: "get",
        url: "/AppAPI/" + type,
        dataType: 'json',
        error: function (rq, textStatus, errorThrown) {
            $.messager.alert("错误", rq.statusText + '(' + rq.status + '):' + rq.responseText, "error");
        },
        success: function (result) { 
            var date = new Date();
            var cate = [];
            date.setDate(date.getDate() - 7);
            for (i = 0; i < 7; i++) {
                date.setDate(date.getDate() + 1);
                cate.push((date.getMonth() + 1) + '月' + date.getDate() + '日');
            }

            $(divid).highcharts({
                chart: {
                    type: 'spline'
                },
                title: {
                    text: title
                },
                subtitle: {
                    text: memo
                },
                xAxis: {
                    categories: ['一月', '二月', '三月', '四月', '五月', '六月',
                                 '七月', '八月', '九月', '十月', '十一月', '十二月']
                },
                yAxis: {
                    title: {
                        text: ytitle
                    },
                    labels: {
                        formatter: function () {
                            return this.value + '°';
                        }
                    }
                },
                tooltip: {
                    crosshairs: true,
                    shared: true
                },
                plotOptions: {
                    spline: {
                        marker: {
                            radius: 4,
                            lineColor: '#666666',
                            lineWidth: 1
                        }
                    }
                },
                series: [{
                    name: '东京',
                    marker: {
                        symbol: 'square'
                    },
                    data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, {
                        y: 26.5,
                        marker: {
                            symbol: 'url(https://www.highcharts.com/demo/gfx/sun.png)'
                        }
                    }, 23.3, 18.3, 13.9, 9.6]
                }, {
                    name: '伦敦',
                    marker: {
                        symbol: 'diamond'
                    },
                    data: [{
                        y: 3.9,
                        marker: {
                            symbol: 'url(https://www.highcharts.com/demo/gfx/snow.png)'
                        }
                    }, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
                }]
            }); 

            $("#chart_add text").each(function (i) { 
                if ($(this).html().indexOf ('Highcharts.com')>=0) {
                    $(this).css("display","none");
                }
            });
        }
    });
} 

function navonclick(docobj) { 
	   var obj=$(docobj);
	    var id = obj.attr('id')  ;
	    for(i=0;i<navlist.length;i++){
			var navitem =navlist[i]; 
	        if(navitem.typeId.trim() ==id)break;
	    }
	    
	    var text = '-'+ docobj.innerText+'-';
	    var MinIco=navitem.MinIco;
	    var url = Onluy.basePath()+navitem.URLLINK;
	    var actiontype ;
	    var WINDOWWIDTH = "720";
	    var WINDOWHEIGHT = "500";
        var i=0;
        if (navitem['WINDOWWIDTH']  )
	    {
	        WINDOWWIDTH = navitem['WINDOWWIDTH'];
	    } 
        if (navitem['WINDOWHEIGHT']  )
	    {
        	WINDOWHEIGHT = navitem['WINDOWHEIGHT'];
	    }  

        if (navitem['RDURL']  )
	    {
    		actiontype = 'RDURL';
	    }  
    	else if (navitem['OPENWINDOW']   )
	    {
    		actiontype = 'OPENWINDOW';
	    }
    	else{
    		actiontype='OPENPANEL';
    	}
	    
	    // alert(id);
	    if(url.length<5){
	         //alert('未定义按钮打开方式！');
	    } 
	     else if (actiontype =='OPENPANEL' ) {
	    	addPanel(id,text ,url);
	        return;
	    }
	    else if (actiontype =='RDURL'  ) {
	    	baseGoUrl(url) ;
	        return;
	    }
	    else if (actiontype =='OPENWINDOW'  ) {
	    	ShowPopWindowUrl(id,text ,url, WINDOWWIDTH, WINDOWHEIGHT);
	        return;
	    }
	    else {
	         alert('未定义按钮打开方式！');
	    } 
	     
}

function inintNav3(obj){ 
	var id=$(obj).attr('id').trim();
    var ul3obj=$('#nav3_'+id);
    $('.nav_3').addClass('displaynone');
    if(ul3obj && ul3obj.html() && ul3obj.html().length>5){
        ul3obj.removeClass('displaynone');
        return;
    }

    var htmlstr='';
    //后台获取下级菜单
    var i=0,j; 
	htmlstr +='<ul class="nav_3" id="nav3_'+id+'"> ';
	for(i=0;i<navlist.length;i++){
		var item =navlist[i];
        var MAXICO='/Images/icos/expbtn.png';
        if(item.pTypeId.trim() !=id)continue;
        htmlstr +='<li';
        for( p in item){ 
	    	 if (p == 'MAXICO')
		    {
	    		MAXICO = item[p].trim();
	    		break;
		    }   
	    }
		
		 htmlstr +=' id="'+item.typeId.trim()+'" onclick="navonclick(this)"> <span style="background-image: url('+Onluy.basePath()+MAXICO+')">&nbsp;</span><label>'+item.typeName+'</label></li> ';
		
	} 
	htmlstr +='</ul>'; 
	$(obj).after(htmlstr); 
}

function inintNav2(obja){
	var id=$(obja).attr('id').trim();
	var title=$(obja).html(); 
    var htmlstr='';
    $('.expbtn').children('label').html(title);
    var i=0,j;
	for(i=0;i<navlist.length;i++){
		var item =navlist[i];
        var MAXICO='/Images/icos/32/plus.png';
        if(item.pTypeId.trim() !=id)continue;
        for( p in item){
            if (p == 'MAXICO')
            {
                MAXICO = item[p].trim();
                break;
            }
        }
        htmlstr +='<a class="nav_2" id="'+item.typeId.trim()+'" ';
		 if(item.childCount>0){
			 htmlstr +='  onclick="inintNav3(this)" ';
		 }else{
			 htmlstr +=' onclick="navonclick(this)" '; 
		 }
		
		htmlstr +='  > ';
		htmlstr +='<span style="background-image: url('+Onluy.basePath()+MAXICO+')">&nbsp;</span> ';
		htmlstr +=item.typeName+' </a>';
		
	} 
	$('#navlist_2').html(htmlstr); 
}

var navlist=[];
function init() { 
	var navstr=$('#__VIEWSTATE').val();
	var jsonstr=Onluy.DES.decrypt(navstr,Onluy.secretkey);
    navlist=JSON.parse(jsonstr);
    
    //alert(jsonstr);
    
	var i=0,navhtml='';
	for( i=0;i< navlist.length;i++){
		var nav=navlist[i]; 
		if(nav.pTypeId =='SYS'){
			navhtml+='<div class="navroot" id="'+nav.typeId+'"> '+nav.typeName +'</div>';
		}
	}
	$('.navroothead').after(navhtml);
	
	
	
    $(".expbtn").bind("click", function(){
    	var winwidth=$(window).width() ;
    	if($('#navpanel').width()>50){
    		$('#navpanel').panel('resize',{
    			width: 50 
    		});
    		$('#centerpanel').panel('resize',{ 
        		left: 50 ,width: winwidth-50 
    		});
    	}
    	else{
    		$('#navpanel').panel('resize',{
    			width: 160 
    		});
    		$('#centerpanel').panel('resize',{ 
        		left: 160 ,width: winwidth-160 
    		});
    	} 
    	
    	
    });
    
    
    $(".navroot").bind("click", function(){
        inintNav2(this);
    });
    
    $(".navroot:first").click(); 
}


$(function () {
    var cssstr = getQueryStringByName('theme'); 
    tabCloseEven(); 
    init();  
    $('#tabs').tabs({
         tabPosition:'left' ,       
        border: false
    }); 
     
    
    
    //InintChart('#chart_add', 'CHARTDAYADD', '新增操作次数', '记录管理员操作新增次数', '新增记录数 ( 次 )');
    //InintChart('#chart_update', 'CHARTDAYAUPDATE', '更新操作次数', '记录管理员操作更新数据次数', '更新记录数 ( 次 )');
    //InintChart('#chart_del', 'CHARTDAYDEL', '删除操作次数', '记录管理员操作删除数据次数', '删除数据记录数 ( 次 )');
    //InintChart('#chart_list', 'CHARTDAYLIST', '查看列表操作次数', '记录管理员查看列表的次数', '查看列表记录数 ( 次 )');

    $('#londing').window('close');
});
 